package com.adee.nowcoder.huawei;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class T020_HJ20 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            if (str.trim().length() == 0) break;
            if(str.length() > 8 && up3(str) && noRepeat3(str)) {
                System.out.println("OK");
            }else {
                System.out.println("NG");
            }
        }
    }

    static boolean up3(String s) {
        int a1 = 0, a2 = 0, a3 = 0, a4 = 0;
        char[] arr = s.toCharArray();
        for (char c : arr) {
            if (c >= 'a' && c <= 'z') {
                a1 = 1;
            }else if (c >= 'A' && c <= 'Z') {
                a2 = 1;
            }else if (c >= '0' && c <= '9') {
                a3 = 1;
            } else {
                a4 = 1;
            }
            if((a1+a2+a3+a4) > 2) {
                return true;
            }
        }
        return false;
    }


    private static boolean noRepeat3(String str) {
        Map<String,Object> map = new HashMap();
        for (int i = 0; i < str.length() - 2; i++) {
            String s3 = str.substring(i, i + 3);
            if (map.containsKey(s3)) return false;
            else map.put(s3, null);
        }
        return true;
    }
}
